package cn.com.zetatech.loader.resolver.service;

/**
 * @author jian.chen@zetatech.com.cn
 * @Description 策略工厂类 ResolverParquetFunctionFactory 用于根据 type 类型动态选择合适的策略。
 * @Date 2024/8/27 11:34
 */
import cn.com.zetatech.loader.util.AnnotationParquetType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class AnnotationResolverParquetFunctionFactory {

    private final Map<String, AnnotationParquetFunction> functionMap = new HashMap<>();

    @Autowired
    public AnnotationResolverParquetFunctionFactory(List<AnnotationParquetFunction> functions) {
        for (AnnotationParquetFunction function : functions) {
            AnnotationParquetType annotation = function.getClass().getAnnotation(AnnotationParquetType.class);
            if (annotation != null) {
                functionMap.put(annotation.value(), function);
            }
        }
    }

    public AnnotationParquetFunction getFunction(String type) {
        return functionMap.get(type);
    }
}

